<?php
namespace src;
use classlib\input;
use src\logic\Cadmin;
use classlib\core\lang;
use classlib\core as C;
use classlib\core\controller;
use src\logic\workflow\doc_executor;
class Cmyself extends controller {
	//我的单据 我已经接受处理的
	public function main() {
		$view = C\view::inst('extjs');
		Cadmin::chkaccess($view);
		$dlang= lang::inst('dd');
		$view->assign('estatus', $dlang->get('wk00001'));
		$view->assign('nstatus', $dlang->get('wk00002'));
		$view->assign_by_ref('title', Cadmin::$name);
		$view->display('workflow/myself.ext.js');
	}

	/**
	 * 获取数据信息列表展示
	 * @return array
	 */
	public function dolist() {
		$view   = C\view::inst('json');
		$userid = Cadmin::chkaccess($view, 'workflow/myself');
		list($start, $limit, $sort) = Cadmin::offset();
		$where  = array('acceptuserid'=>$userid);
		$name   = input::post('name');
		if(!empty($name)) {
			$where[]= array('name', '%'.$name.'%', \classlib\orm::OP_LIKE);
		}
		$status= input::post('nstatus');
		if (is_numeric($status)) {
			$where[]= array('status', $status, \classlib\orm::OP_EQ);
		}
		$eid = input::post('eid');
		if (is_numeric($eid)) {
			$where[]= array('executionid', $eid, \classlib\orm::OP_EQ);
		}
		$sdate   = input::post('sdate');
		if ($sdate) {
			$where[]= array('accepttime', $sdate, \classlib\orm::OP_GT);
		}
		$edate   = input::post('edate');
		if ($edate) {
			$where[]= array('accepttime', $edate, \classlib\orm::OP_LT);
		}
		$orm    = C\model::load('main.proc.nodestate');
		$total  = $orm->get_total($where);
		$list   = array();
		if ($total > 0) {
			$list = $orm->get_list($start, $limit, $where, '*', $sort);
			$eorm = C\model::load('main.proc.execution');
			$worm = C\model::load('main.proc.workflow');
			$norm = C\model::load('main.proc.node');
			foreach ($list as &$item) {
				$execution = $eorm->get_one($item['executionid']);
				$item['stopusername']  = $execution['stopusername'];
				$item['applyusername'] = $execution['applyusername'];
				$item['estatus']       = $execution['status'];
				$item['completetime']  = doc_executor::datetime($item['completetime']);
				$item['expire']        = doc_executor::datetime($item['expire']);
				$workflow = $worm->get_one($item['workflowid']);
				$item['workflowname']  = $workflow['name'];
				$node     = $norm->get_one($item['nodeid']);
				$item['name']          = $node['name'];
			}
		}
		$view->assign_by_ref('total', $total);
		$view->assign_by_ref('dataset', $list);
		$view->display();
	}
}